package nl.blindwars;

import java.util.ArrayList;

import nl.blindwars.model.City;
import nl.blindwars.model.Country;
import nl.blindwars.model.Map;
import nl.blindwars.model.Player;

public class Game {

	private ArrayList<Player> players;

	private Map map;
	
	public Game() {
		players = createPlayers();
		
		map = new Map();
		
		newGame();
	}

	/**
	 * A test method to craete a bunch of players.
	 * @todo remove this method.
	 * @return list of players.
	 */
	private ArrayList<Player> createPlayers() {
		players = new ArrayList<Player>();
		
		players.add(new Player("Player 1", true));
		players.add(new Player("Computer 1", false));
		players.add(new Player("Computer 2", false));
		players.add(new Player("Computer 3", false));
		
		return players;
	}
	
	public ArrayList<Player> getPlayers() {
		return players;
	}

	public boolean addPlayer(Player player) {
		return players.add(player);
	}
	
	public boolean removePlayer(Player player) {
		return players.remove(player);
	}

	/**
	 * Prepare everything for a new round/game.
	 */
	public void newGame() {
		ArrayList<City> cities = map.getCities();
		
		int index;
		for(City city : cities) {
			index = (int) Math.floor((Math.random() * 4));
			Player player = players.get(index);
			player.addCity(city);
			city.setOwner(player);
		}
		
		for(Player player : players) {
			System.out.println(player.getName() + " has " + player.getNumberOfCities() + " cities.");
		}
	}

	public void nextTurn() {

	}

	public void save() {

	}

	public void load() {

	}

	public void attack(Country ownCountry, Country enemyCountry) {

	}

	public void cancelAttack() {

	}
}
